package com.logic.saas.pojo;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.logic.saas.util.SysUtil;
import com.logic.saas.util.annotation.Column;
import com.logic.saas.util.annotation.Table;
import com.logic.saas.util.annotation.UniqueConstraint;

@Table(name = "kind", uniqueConstraints={@UniqueConstraint(columnNames={"short_name"})})
public class Kind extends BasePojo implements Serializable {
	
    private static final long serialVersionUID = 3148176768559230877L;

    @Column(name = "short_name")
    private String shortName;
    
    @Column(name = "full_name")
    private String fullName;
    
    @Column(name="editable")
    private boolean editable;
    
    //other fields
    private List<Qcode> codes;
    /** default constructor */
    public Kind(){
    	
    }
    
    public Kind(String shortName, String fullName,boolean editable){
    	this.shortName = shortName;
        this.fullName = fullName;
        this.editable = editable;
    }
    
    public Kind(String shortName, String fullName, Timestamp latestModifyDate, Integer latestModifyBy, Timestamp createdDate, Integer createdBy) {
        this.shortName = shortName;
        this.fullName = fullName;
        this.latestModifiedDate= latestModifyDate;
        this.latestModifiedBy = latestModifyBy;
        this.createdDate = createdDate;
        this.createdBy = createdBy;
    }
    
	public List<Qcode> getCodes() {
		return codes;
	}

	public void setCodes(List<Qcode> codes) {
		this.codes = codes;
	}

	public String getShortName() {
		return shortName;
	}
	public void setShortName(String shortName) {
		this.shortName = shortName;
	}
	public String getFullName() {
		return fullName;
	}
	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public boolean isEditable() {
		return editable;
	}

	public void setEditable(boolean editable) {
		this.editable = editable;
	}

	@Override
	public String getDisplayText() {
		if(StringUtils.isNotBlank(shortName)){
			String tempStr="["+shortName.trim()+"] "+SysUtil.trim(fullName);
		    return SysUtil.cutoffString(tempStr,displayTextLength);
		}else
			return "";
	}
	
	/**
	 * 重写equal方法，比较Kind是否相等,不比ID
	 */
	@Override
	public boolean equals(Object obj) {
		boolean equal = false;
		
		if(obj != null){
			if(this.getClass() == obj.getClass()){
				Kind k = (Kind) obj;
				if(
					//((this.getId() == null && k.getId() == null) || (this.getId() != null && k.getId() != null && this.getId().equals(k.getId()))) &&
					((this.getShortName() == null && k.getShortName() == null) || (this.getShortName() != null && k.getShortName() != null && this.getShortName().equals(k.getShortName()) )) &&
					((this.getFullName() == null && k.getFullName() == null) || (this.getFullName() != null && k.getFullName() != null && this.getFullName().equals(k.getFullName()))) &&
					this.isEditable() == k.isEditable()
				 ){
					equal = true;
				}
			}
		}
		
		return equal;
	}

	
}

